package org.example.handler;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author beikbei
 * @version 1.0
 * @description: TODO
 * @date 2024/5/11 11:01
 */
public class MyLoginSuccessHandler implements AuthenticationSuccessHandler {
    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        // 拿到登录用户的信息
        UserDetails userDetails = (UserDetails) authentication.getPrincipal();
        System.out.println("用户名: " + userDetails.getUsername());
        System.out.println("一些操作...");
        // 重定向到主页等待。。。。
        response.sendRedirect(request.getContextPath() + "/main.html");
    }
}
